package ar.edu.unq.mongodbexample.persistence.commands;

import com.mongodb.DBObject;
import com.mongodb.util.JSON;

import flexjson.JSONSerializer;

/**
 * TODO: description
 * 
 * @param <T>
 */
public class CreateCommand<T> extends Command<T> {

    private T entity;

    public CreateCommand(final Class clazz) {
        super(clazz);
    }

    public void run() {
        JSONSerializer serializer = new JSONSerializer();
        String serializedEntity = serializer.serialize(this.getEntity());

        this.getDBCollection().insert((DBObject) JSON.parse(serializedEntity));
    }
}
